//
//  UCToolbarSetting.swift
//  UICreate
//
//  Created by 范晓鑫 on 2021/10/27.
//

import UIKit

extension UCSetting where TargetType: UIToolbar {
    ///样式
    public static func style(_ style: UIBarStyle) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.barStyle = style
        })
    }
    ///items
    public static func items(_ items: [UIBarButtonItem]?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.items = items
        })
    }
    ///半透明
    public static func translucent(_ translucent: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.isTranslucent = translucent
        })
    }
    ///barTintColor
    public static func tint(bar color: UIColor?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.barTintColor = color
        })
    }
    ///  setBackgroundImage(_ backgroundImage: UIImage?, forToolbarPosition topOrBottom: UIBarPosition, barMetrics: UIBarMetrics)
    public static func bg(_ image:UIImage?, for topOrBottom: UIBarPosition, metrics: UIBarMetrics = .default) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.setBackgroundImage(image, forToolbarPosition: topOrBottom, barMetrics: metrics)
        })
    }
    ///  setShadowImage(_ shadowImage: UIImage?, forToolbarPosition topOrBottom: UIBarPosition)
    public static func shadow(_ image:UIImage?, for topOrBottom: UIBarPosition) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.setShadowImage(image, forToolbarPosition: topOrBottom)
        })
    }
    ///standardAppearance
    @available(iOS 13.0, *)
    public static func appearance(_ appearance:UIToolbarAppearance) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.standardAppearance = appearance
        })
    }
    ///compactAppearance
    @available(iOS 13.0, *)
    public static func appearance(compact appearance:UIToolbarAppearance?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.compactAppearance = appearance
        })
    }
    ///scrollEdgeAppearance
    @available(iOS 15.0, *)
    public static func appearance(scroll appearance:UIToolbarAppearance?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.scrollEdgeAppearance = appearance
        })
    }
    ///compactScrollEdgeAppearance
    @available(iOS 15.0, *)
    public static func appearance(compactScroll appearance:UIToolbarAppearance?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.compactScrollEdgeAppearance = appearance
        })
    }
    /// delegate
    public static func delegate(_ delegate:UIToolbarDelegate?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.delegate = delegate
        })
    }
}
